package data_structure;

public class leetcode_0572 {
    public boolean isSubtree(TreeNode root, TreeNode subRoot) {
        if(subRoot==null) return true;
        if(root==null&&subRoot!=null) return false;
        return (iseq(root,subRoot)||isSubtree(root.left,subRoot)||isSubtree(root.right,subRoot));
    }
    public boolean iseq(TreeNode node,TreeNode subnode){
        if(node==null&&subnode!=null) return false;
        if(node!=null&&subnode==null) return false;
        if(node!=null&&subnode!=null){
            if(node.val!=subnode.val) return false;
            return (iseq(node.left,subnode.left)&&iseq(node.right,subnode.right));
        }
        else return true;
    }
}
